package com.zm.campus.controller;


import com.zm.campus.pojo.RespBean;
import com.zm.campus.pojo.User;
import com.zm.campus.service.IUserService;

import com.zm.campus.vo.UpdateSignVo;
import com.zm.campus.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zm
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    //根据token从redis中获取当前登录用户的LoginReturnVo
    @PostMapping("getNowUserInfoByServer")
    public RespBean getNowUserInfo(String token){
        return userService.getNowUserInfo(token);
    }

    //通过用户id获取当前用户信息
    @RequestMapping("getUserById")
    public RespBean getUserById(String userId){
        return userService.getUserById(userId);
    }

    //修改用户头像
    @PostMapping("updateAvatar")
    public RespBean updateAvatar(@RequestBody MultipartFile headImgeFile, String userId) throws IOException {
        System.out.println(headImgeFile.toString());
        return userService.updateAvatar(headImgeFile,userId);
    }
    //完善个人信息
    @PostMapping("updateUserInfo")
    public RespBean updateUserInfo(@RequestBody UserInfoVo userInfoVo){
        return userService.updateUserInfo(userInfoVo);
    }
    //更新个性签名
    @PostMapping("updatePersonSign")
    public RespBean updatePersonSign(@RequestBody UpdateSignVo updateSignVo){
        return userService.updatePersonSign(updateSignVo.getSign(),updateSignVo.getUserId());
    }

    //超级管理员授权用户获得管理员身份
    @PostMapping("authUserToAdmin")
    public RespBean authUserToAdmin(String supAdmin,String beUserId,String role){//接收当前要执行授权人的角色，还有被授权用户的id,要授权用户的角色
        return userService.authUserToAdmin(supAdmin,beUserId,role);
    }
    //根据用户id获取用户基本信息
    @GetMapping("getUserInfoByUid")
    public RespBean getUserInfoByUid(String userId){
        return userService.getUserInfoByUid(userId);
    }

}
